package second50;

import java.util.Arrays;

public class T0063 {
    int[][] ints;

    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if (obstacleGrid[0][0] == 1) return 0;
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        ints = new int[m][n];
        for (int[] i : ints) Arrays.fill(i, -1);
        ints[0][0] = 1;
        return a(m - 1, n - 1, obstacleGrid);
    }

    public int a(int m, int n, int[][] ob) {
        if (ob[m][n] == 1) return 0;
        if (m < 0 || n < 0) return 0;
        if (ints[m][n] == -1) {
            ints[m][n] = a(m - 1, n, ob) + a(m, n - 1, ob);
        }
        return ints[m - 1][n - 1];
    }


}
